package club.mzywucai.blog.file_system.controller;

import club.mzywucai.blog.file_system.pojo.domain.DelNotActiveUser;
import club.mzywucai.blog.file_system.pojo.domain.JsonData;
import club.mzywucai.blog.file_system.pojo.vo.KeyAndValueVo;
import club.mzywucai.blog.file_system.service.CheckBoxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author mzywucai
 * @Description 下拉框的选择 Controller.
 * @date 2019/1/30
 */
@RestController
public class CheckBoxController {
    @Autowired
    CheckBoxService checkBoxService;

    /**
     * @Description 文件上传选择类别的大类别：文档类、系统类、安装包类和音频类 ... 
     * @author mzywucai
     * @time 2019-02-08
     * @see 
     * @return   java.lang.Object
     * @params  []
     */
    @RequestMapping("/api/fileCategory/levelOne")
    public Object getFileCategoryLevelOne() {

        List<KeyAndValueVo> fileCategoryLevelOne;
        try {
            fileCategoryLevelOne =
                    checkBoxService.getFileCategoryLevelOne();
        } catch (Exception e) {
            return JsonData.buildError("数据库系统异常");
        }
        if (null != fileCategoryLevelOne) {
            return JsonData.buildSuccess(0, fileCategoryLevelOne, "ok");
        } else {
            return JsonData.buildError("数据库系统异常");
        }
    }

    /**
     * @Description 大类别下的小类别：如安装包下的mac安装包、windows安装包和linux安装包。
     * @author mzywucai
     * @time 2019-02-08
     * @see 
     * @return   java.lang.Object
     * @params  [parentId]
     */
    @RequestMapping("/api/fileCategory/levelTwo/{parent_id}")
    public Object getFileCategoryLevelTwo(@PathVariable("parent_id") String parentId) {
        List<KeyAndValueVo> fileCategoryLevelOne;
        try {
            fileCategoryLevelOne =
                    checkBoxService.getFileCategoryLevelTwo(parentId);
        } catch (Exception e) {
            return JsonData.buildError("数据库系统异常");
        }

        if (null != fileCategoryLevelOne) {
            return JsonData.buildSuccess(0, fileCategoryLevelOne, "ok");
        } else {
            return JsonData.buildError("无此父级ID");
        }
    }
}
